package com.zhuiYun.project.api.handworkdiycollection.controller;
import com.zhuiYun.project.api.handworkdiycollection.model.HandworkDiyCollectionModel;
import com.zhuiYun.project.api.handworkdiycollection.service.HandworkDiyCollectionService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
 * @ClassName handworkdiyController
 * @Description TODO
 * @Author yangze
 * @Date 2023/4/6 13:43
 **/
@RestController
@CrossOrigin
@Api(tags = "手工diy收藏")
@RequestMapping("/handworkDiyCollection")
@Slf4j
public class HandworkDiyCollectionController extends BaseController {

    @Resource
    private HandworkDiyCollectionService handworkDiyCollectionService;

    /**
     * @param userId
     * @param diyCommodityName
     * @Author yangze
     * @Description TODO 查询收藏的手工diy
     * @Date 2023/4/6 13:44
     * @Return CommonResult
     */
    @GetMapping("/selectHandworkDiyCollectionList")
    public CommonResult selectHandworkDiyCollection(Integer userId, String diyCommodityName) throws CommonException {
        CommonResult commonResult = handworkDiyCollectionService.selectHandworkDiyCollectionList(userId, diyCommodityName);
        return commonResult;
    }

    /**
     * @param id
     * @Author yangze
     * @Description TODO 取消收藏
     * @Date 2023/4/6 20:07
     * @Return
     */
    @DeleteMapping("/delete")
    public CommonResult deleteById(Integer id) throws CommonException {
        CommonResult commonResult = handworkDiyCollectionService.deleteById(id);
        return commonResult;
    }
    /**
     * @param handworkDiyCollectionModel
     * @Author yangze
     * @Description TODO  根据用户id和diy商品id取消收藏
     * @Date 2023/4/10 14:54
     * @Return
     */
    @PostMapping("/deleteByUserIdAndDiyId")
    public CommonResult deleteByUserIdAndDiyId(@RequestBody HandworkDiyCollectionModel handworkDiyCollectionModel) throws CommonException {
        CommonResult commonResult = handworkDiyCollectionService.deleteByUserIdAndDiyId(handworkDiyCollectionModel);
        return commonResult;
    }

    /**
     * @Author yangze
     * @Description TODO  根据用户id收藏diy
     * @Date 2023/4/7 16:37
     * @Return
     */
    @PostMapping("/insertHandworkDiyCollection")
    public CommonResult insertHandworkDiyCollection(@RequestBody HandworkDiyCollectionModel handworkDiyCollectionModel) throws CommonException {
        CommonResult commonResult = handworkDiyCollectionService.insertHandworkDiyCollection(handworkDiyCollectionModel);
        return commonResult;
    }

    /**
     * @param userId,diyCommodityId
     * @Author yangze
     * @Description TODO 查询是否收藏 0未收藏 1已收藏
     * @Date 2023/4/10 10:30
     * @Return commonResult
     */
    @GetMapping("/selectIsCollection")
    public CommonResult selectIsCollection(Integer userId, Integer diyCommodityId) throws CommonException {
        CommonResult commonResult = handworkDiyCollectionService.selectIsCollection(userId, diyCommodityId);
        return commonResult;
    }

}